import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);


import Home from '@/components/Home'
import List from '@/components/List'
import Cart from '@/components/Cart'
import User from '@/components/User'

import Order from '@/components/Order'

import InnerPage from '@/components/InnerPage';
// import Follow from '@/components/Follow'
// import Column from '@/components/Column'
// import User from '@/components/User'
import Login from '@/components/Login'
// import Reg from '@/components/Reg'
import Detail from '@/components/Detail'
// import AppError from '@/common/AppError'
import AppHeader from '@/common/AppHeader'
import AppFooter from '@/common/AppFooter'

let routes=[
  {path:'/order',components:{
    default:Order
  }},
  {path:'/home',components:{
    default:Home,
    AppHeader,
    AppFooter
  }},
  {path:'/list',components:{
    default:List,
    AppHeader,
    AppFooter
  }},
  {path:'/cart',
    name:'cart',
    components:{
      default:Cart,
      AppFooter
    }},
  {path:'/user',components:{
    default:User,
    AppFooter
  }},
  {path:'/inner_page',components:{
    default:InnerPage,
  }},
  // {path:'/follow',component:Follow},
  // {path:'/column',component:Column},
  // {path:'/detail/:id',component:Detail},
  {path:'/detail/:id',
    name:'detail',
    component:Detail},
  // {path:'/user',component:User},
  {path:'/login',component:Login},
  // {path:'/reg',component:Reg},
  {path:'/',redirect:'/home'}
  // {path:'*',component:AppError}
];

const router = new VueRouter({routes});

router.beforeEach((to, from, next) => {
  // console.log(to)
  if (to.path === '/login') {
    // if (localStorage.getItem('isLogin') === 'ok') {
    //   next() // 该方法表示当条件满足继续执行
    // } else {
    //   alert('未登录')
    //   next('/register') // 跳转到注册页面
    // }
    next();
  } else {
    if(window.localStorage["user"]){
      next();
    }else{
      next('/login');
    }
  }
})

export default router;